Option Strict Off
Option Explicit On
Friend Class NameNIP
	Inherits System.Windows.Forms.Form
	' string for on-line game
	'
	Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
    '	On Error GoTo er
		Form1.WaitForPlayer = False
		Form1.TryConnect = False
		Form1.NickName = txtName.Text
		If Form1.PlayOffline Then
			Form1.VisitorName = txtIP.Text
			Me.Close()
			Form1.PrepareGame()
		Else ' on-line game
			If Form1.Host Then ' listen to port for incoming calls
        If Form1.SockListen.GetState() <> Winsock_Control.WinsockStates.Connected Then Form1.SockListen.Close()
        'Form1.SockClient.Protocol = MSWinsockLib.ProtocolConstants.sckTCPProtocol
        Form1.SockListen.LocalPort = CShort(txtPort.Text)
        Form1.SockListen.Listen()
				Form1.WaitForPlayer = True
				Me.Close()
        'frmTryConnect.GetinitWaitting()
        'frmTryConnect.ShowDialog()
				Exit Sub
			Else ' i am guest, connect to host IP
				Form1.HostName = txtIP.Text
				Call Me.Connect()
        Me.Close()
        'frmTryConnect.GetinitWaitting()
        'frmTryConnect.ShowDialog()
			End If
		End If
		Exit Sub
er: 
		MsgBox(Err.Description)
	End Sub
	Public Sub Connect()
    'On Error GoTo er
		Form1.TryConnect = True
    'If Form1.SockClient.GetState <> Winsock_Control.WinsockStates.Connected Then Form1.SockClient.Close()
    'Form1.SockClient.Protocol = MSWinsockLib.ProtocolConstants.sckTCPProtocol
    Form1.SockClient.RemoteIP = Form1.HostName
		Form1.SockClient.RemotePort = CShort(txtPort.Text)
		Form1.SockClient.Connect()

	End Sub
	Private Sub NameNIP_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Call ChangeLabels()
		txtPort.Text = CStr(777)
	End Sub
	Private Sub ChangeLabels()
		Label1(2).Visible = Not Form1.PlayOffline
		txtPort.Visible = Not Form1.PlayOffline
		If Form1.PlayOffline Then
      Label1(0).Text = My.Resources.MSG_VISITOR_NICKNAME_LABEL
      txtIP.Text = My.Resources.MSG_BLUE
      txtName.Text = My.Resources.MSG_RED
      Label1(1).Text = My.Resources.MSG_HOST_NICKNAME_LABEL
		Else
			If Form1.NickName = "Guest" And Form1.Host = True Then Form1.NickName = "Host"
      Label1(0).Text = My.Resources.MSG_IP
			Label1(0).Enabled = Not Form1.Host
			txtIP.Enabled = Not Form1.Host
      txtIP.Text = Form1.HostName 'My.Settings.RemoteIP
			txtName.Text = Form1.NickName
		End If
	End Sub
End Class